---
- name: Установка и конфигурирование MariaDB
  hosts: ecstasy_server
  become: yes
  gather_facts: no
  vars_files:
    - ../../roles/vars/ecstasy-main.yaml
    - ../../roles/vars/ecstasy-mariadb.yaml
  tasks:
    - name: Установка MariaDB
      apt:
        name: "{{ item }}"
        update_cache: yes
        autoclean: yes
        autoremove: yes
        state: latest
      loop:
        - mariadb-client
        - mariadb-server

    - name: Установка зависимостей
      apt:
        name: "{{ item }}"
        state: present
        autoclean: yes
        autoremove: yes
      loop:
        - python3-mysqldb
        - pkg-config

    - name: Создание базы данных
      community.mysql.mysql_db:
        login_user: root
        login_password: "{{ mysql_root_password }}"
        name: "{{ mariadb_database }}"
        state: present

    - name: Создание пользователя и прав на базу
      community.mysql.mysql_user:
        login_user: root
        login_password: "{{ mysql_root_password }}"
        name: "{{ mariadb_user }}"
        password: "{{ mariadb_password }}"
        priv: "{{ mariadb_database }}.*:ALL,GRANT"
        state: present

